package com.zzw.redis;


import com.zzw.until.FastJsonUntil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.ArrayList;
import java.util.List;

@Component
public class SynUntil {

    @Autowired
    private JedisPool jedisPool;

    @Autowired
    private RedisMsgPubSubListener redisMsgPubSubListener;

    public void subscribe(){
        Jedis jedis = jedisPool.getResource();
        jedis.subscribe(redisMsgPubSubListener,"redisChatTest");
    }

    public void publish(String msg){
        List<Integer> list = new ArrayList<Integer>();
        list.add(1);
        list.add(2);
        Jedis jedis = jedisPool.getResource();
        jedis.publish("sync", FastJsonUntil.listToJson(list));
        jedis.publish("sync","hello");
    }
}
